﻿#ifndef IPC_H
#define IPC_H

#include <QThread>
#ifndef NO_WIDGETS
#include <QWidget>
#endif
#include <QTimer>
#include <time.h>
#include <QNetworkReply>
#include <QEventLoop>
#include "oeasycommon.h"
#include "configfile.h"
#include "HCNetSDK.h"
#include "PlayM4.h"
#include "recognize.h"
#include "sms.h"

class IPC : public QThread
{
    Q_OBJECT
public:
#ifdef NO_WIDGETS
    explicit IPC(QString &proxyId, QString ipcId, STRUCT_IPC_INFO &ipcInfo, STRUCT_RECOG_INFO &faceInfo, STRUCT_RECOG_INFO &plateInfo);
#else
    explicit IPC(QString &proxyId, QString ipcId, STRUCT_IPC_INFO &ipcInfo, STRUCT_RECOG_INFO &faceInfo, STRUCT_RECOG_INFO &plateInfo, QWidget *widget);
#endif
    ~IPC();
    QString m_id;
    QString m_proxyId;
    STRUCT_IPC_INFO &m_ipcInfo;
    bool m_devState; //设备在线状态
    bool m_mdStatus;
    QWidget *m_wVideo;
    LONG m_lUserID;
    LONG m_lRealPlayHandle;
    LONG m_lRealPlayHandle1;
    LONG m_lAlarmChanHandle;
    QByteArray m_frame_main;
    QByteArray m_frame_second;

private:
    STRUCT_RECOG_INFO &m_faceInfo;
    STRUCT_RECOG_INFO &m_plateInfo;
    SMS *m_sms0;
    SMS *m_sms1;

    Recognize *m_face;
    Recognize *m_plate;
    QEventLoop *m_eventLoop;
    time_t m_lastMotionTime;
    time_t m_lastCarTime;
    time_t m_lastFaceTime;
    time_t m_lastStrangerTime;

    void devInit();
    void devAntiInit();

protected:
    void run();

signals:
    void loginOver(long, long, long);
    void motionAlarm();
    void packetReady(QByteArray);
    void packetReady1(QByteArray);
    void faceSuccess(QString, QString, QByteArray jpg);
    void postPic(QByteArray);
    void postTmpPic(QByteArray);
    void postReport(QByteArray);
    void postBigData(QByteArray);
    void sendMsgToTargetCli(QByteArray);
public slots:
    void onLoginOver(long, long, long);
    void onMotionAlarm();
    void onTimeout();
    void onFacePostOver(const QByteArray &jpg, const QByteArray &data);
    void onPlatePostOver(const QByteArray &jpg, const QByteArray &data);
    void startSMS(QString ip, int port, QString code);
    void stopSMS0();
    void stopSMS1();
    void onIPCSyncTime();

public:
    QString GetCamerId();
};

#endif // IPC_H
